﻿
<form method="post" id="form1">
    @Html.AntiForgeryToken()
    <div class="querybar">
        <table cellpadding="0" cellspacing="1" border="0" width="100%">
            <tr>
                <td>
                    应用名称：<input type="text" class="mytext" id="Title" name="Title" value="" style="width:150px" />
                    应用地址：<input type="text" class="mytext" id="Address" name="address" value="" style="width:220px" />
                    <input type="button" name="Search" onclick="query();" value="&nbsp;&nbsp;查&nbsp;询&nbsp;&nbsp;" class="mybutton" />
                    <input type="button" onclick="edit(); return false;" value="添加应用" class="mybutton" />
                    <input type="button" onclick="del(); return false;" value="删除所选" class="mybutton" />
                </td>
            </tr>
        </table>
    </div>
    <input type="hidden" name="checkbox_app" id="checkbox_app" value="" />
    <table id="listtable"></table>
    <div class="buttondiv"></div>
</form>

<script type="text/javascript">
    var appid = '@ViewData["appId"]';
    var iframeid = '@ViewData["tabId"]';
    var typeid = '@ViewData["typeId"]';
    var dialog = new RoadUI.Window();
    var curPageSize;
    var curPageNumber;
    $(function ()
    {
        $("#listtable").jqGrid({
            url: "Query?@Html.Raw(ViewData["query"])",
            postData: { "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val(), "appid": appid, "typeid": typeid },
            mtype: 'POST',
            datatype: "json",
            colNames: ['应用名称', '应用地址', '应用分类', '操作'],
            colModel: [
                { name: 'Title', index: 'Title' },
                { name: 'Address', index: 'Address', align: "left" },
                { name: 'TypeTitle', index: 'Type', align: "left", width: 50 },
                { name: 'Opation', index: '', sortable: false, title: false, align: "left", width: 50 }
            ],
            sortname: "Title",
            sortorder: "asc",
            height: '100%',
            multiselect: true,
            width: $(window).width(),
            loadComplete: function ()
            {
                var gridObj = $("#listtable");
                var records = gridObj.getGridParam("userData");
                curPageSize = records.pagesize;
                curPageNumber = records.pagenumber;
                $(".buttondiv").html(RoadUI.Core.getPager1(records.total, records.pagesize, records.pagenumber, "query"));
            }
        });
    });
    $(window).resize(function ()
    {
        $("#listtable").setGridWidth($(window).width());
    });
    function query(size, number)
    {
        var data = {
            __RequestVerificationToken: $("input[name='__RequestVerificationToken']").val(),
            Title: $("#Title").val(), Address: $("#Address").val(), typeid: typeid,
            pagesize: size, pagenumber: number
        };
        $("#listtable").setGridParam({ postData: data }).trigger("reloadGrid");
    }
    function edit(id)
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: (id ? "编辑" : "添加") + "应用程序", width: 700, height: 360, url: 'Edit?pagesize=' + curPageSize + "&pagenumber=" + curPageNumber + '&id=' + (id || "") + '&@Html.Raw(ViewData["query"])', opener: parent, openerid: iframeid });
    }
    function editButton(id)
    {
        dialog.open({ id: "window_" + appid.replaceAll('-', ''), title: "编辑按钮", width: 900, height: 380, url: 'Button?pagesize=' + curPageSize + "&pagenumber=" + curPageNumber + '&id=' + (id || "") + '&@Html.Raw(ViewData["query"])', opener: parent, openerid: iframeid });
    }
    function checkAll(checked)
    {
        $("input[name='checkbox_app']").prop("checked", checked);
    }
    function del()
    {
        var rowIds = $("#listtable").jqGrid('getGridParam', 'selarrrow');
        if (rowIds.length==0)
        {
            alert("您没有选择要删除的项!");
            return false;
        }
        if (!confirm('您真的要删除所选应用吗?'))
        {
            return false;
        }
        $.ajax({
            url: "Delete?" + "@Html.Raw(ViewData["query"])" + "&pagesize=" + curPageSize + "&pagenumber=" + curPageNumber,
            data: { "ids": rowIds.join(","), "__RequestVerificationToken": $("input[name='__RequestVerificationToken']").val() },
            type: "post",
            success: function (txt)
            {
                alert(txt);
                query(curPageSize, curPageNumber);
            }
        });
        return true;
    }
</script>
